const express = require('express');
const router = express.Router();
const { protect } = require('../middlewares/authMiddleware');
const {
  addFriend,
  acceptFriend,
  rejectFriend,
  deleteFriend,
  getFriends
} = require('../controllers/friendController');

/**
 * @swagger
 * /friend/add:
 *   post:
 *     summary: 添加好友
 *     tags: [Friend]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               userId:
 *                 type: string
 *             eaxmple:
 *               userId: "680ca346c07aa49ddf3103da"
 *     responses:
 *       201:
 *         description: 好友请求发送成功
 *       400:
 *         description: 好友请求已存在
 *       500:
 *         description: 添加好友失败
 */
router.post('/add', protect, addFriend);

/**
 * @swagger
 * /friend/accept/{id}:
 *   post:
 *     summary: 接受好友请求
 *     tags: [Friend]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: string
 *         required: true
 *         description: 好友请求ID
 *     responses:
 *       200:
 *         description: 好友请求接受成功
 *       404:
 *         description: 好友请求未找到
 *       500:
 *         description: 接受好友请求失败
 */
router.post('/accept/:id', protect, acceptFriend);

/**
 * @swagger
 * /friend/reject/{id}:
 *   post:
 *     summary: 拒绝好友请求
 *     tags: [Friend]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: string
 *         required: true
 *         description: 好友请求ID
 *     responses:
 *       200:
 *         description: 好友请求拒绝成功
 *       404:
 *         description: 好友请求未找到
 *       500:
 *         description: 拒绝好友请求失败
 */
router.post('/reject/:id', protect, rejectFriend);

/**
 * @swagger
 * /friend/{id}:
 *   delete:
 *     summary: 删除好友
 *     tags: [Friend]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         schema:
 *           type: string
 *         required: true
 *         description: 好友关系ID
 *     responses:
 *       200:
 *         description: 好友删除成功
 *       404:
 *         description: 好友未找到
 *       500:
 *         description: 删除好友失败
 */
router.delete('/:id', protect, deleteFriend);

/**
 * @swagger
 * /friend:
 *   get:
 *     summary: 获取好友列表
 *     tags: [Friend]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 好友列表获取成功
 *       500:
 *         description: 获取好友列表失败
 */
router.get('/', protect, getFriends);

module.exports = router;